package Econf_Audio;

import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.FloatControl;
import javax.sound.sampled.Line;
import javax.sound.sampled.Line.Info;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.Port;

public class ControlSound
{	
	public static void modifierVolume(float prctVolume, Port.Info...portsInfo) throws LineUnavailableException 
	{	
		for (Info info : portsInfo)
		{
//			System.out.print(info);
			
			if (AudioSystem.isLineSupported(info))
			{					
				Line lineOut = AudioSystem.getLine(info);
				lineOut.open();				
				
				FloatControl controlIn = (FloatControl) lineOut.getControl(FloatControl.Type.VOLUME);
				
//				System.out.print("\tvolume : "+(100* controlIn.getValue()/controlIn.getMaximum())+" %");
				controlIn.setValue(prctVolume/100);
//				System.out.println(" ==> "+(100* controlIn.getValue()/controlIn.getMaximum())+" %");
				
				lineOut.close();
			}
			else System.out.println("\tAudioMixer not supported");
		}
	}
	
//	public static void main(String...args) throws LineUnavailableException
//	{
//		modifierVolume(50,Port.Info.LINE_OUT, Port.Info.HEADPHONE, Port.Info.SPEAKER);
//	}
}